import uvicorn
from fastapi import FastAPI
from starlette.middleware.cors import CORSMiddleware
from api import api_router
from realtime_stream.socketio_server import sio, get_routes
from socketio import ASGIApp

app = FastAPI()

app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],  # 允许的前端源
    allow_credentials=False,
    allow_methods=["*"],  # 允许的请求方法
    allow_headers=["*"],  # 允许的请求头
)

# 注册API路由
app.include_router(api_router)

# 注册流媒体相关HTTP路由
get_routes(app)

# 合并ASGI应用
asgi_app = ASGIApp(sio, other_asgi_app=app)

if __name__ == '__main__':
    uvicorn.run(asgi_app, host='127.0.0.1', port=5000)